from odoo import api, exceptions, fields, models, _


class Guest(models.Model):
    _name = 'check.guest'
    _description = "hotel register"
    _inherit = ['mail.thread', 'mail.activity.mixin']
    _rec_name = 'name'

    name = fields.Char(
        string="宾客姓名",
        required=True,
    )

    gender = fields.Selection(
        [
            ('0', '男'),
            ('1', '女'),
        ],
        "宾客性别",
        default="1",
    )

    age = fields.Selection(
        [
            ("i".format(i), i) for i in range(100)
        ],
        string="宾客年龄"
    )

    Id_type = fields.Selection(
        [
            ('0', '身份证'),
            ('1', '港澳通行证')
        ],
        "证件类型", default='0'
    )

    Id_number = fields.Char(
        "证件编号", required=True)

    address = fields.Char(
        "宾客地址", required=True
    )

    tel = fields.Char(
        "联系电话", required=True
    )

    source = fields.Selection(
        [
            ('0', '湖北省'),
            ('1', '北京市')
        ],
        "宾客来源", default='0'
    )

    company_title = fields.Char(
        "公司名称", required=True
    )

    company_address = fields.Char(
        "公司地址", required=True
    )

    note = fields.Char(
        "备注信息"
    )

    guest_img = fields.Binary(
        "主客照片"
    )

    chape_way = fields.Selection(
        [
            ('0', 'None'),
        ],
        "促销方案", default='0',
    )

    sale_person = fields.Many2one(
        'res.partner',
        "销售人员",
    )

    odoo_Id = fields.Char(
        "手工单号"
    )

    guest_num = fields.Integer(
        "宾客人数"
    )

    live_day = fields.Integer(
        "预住时长",
    )

    leave_day = fields.Date(
        "预离日期",
        default=lambda s: fields.Date.today(),
    )

    half_day = fields.Boolean(
        '半天房',
    )

    night_day = fields.Boolean(
        '午夜房',
    )

    holi_day = fields.Boolean(
        '假期房',
    )

    olcok_day = fields.Boolean(
        '钟点房',
    )

    Money = fields.Monetary(
        '押金金额',
        'currency_id',
    )

    # price helper
    currency_id = fields.Many2one('res.currency',
                                  default=lambda self: self.env.user.company_id.currency_id, )  # price helper

    pay_way = fields.Selection(
        [
            ('0', '现金'),
            ('1', '支付宝'),
            ('2', '微信'),
            ('3', '银行卡')
        ],
        "支付方式",
        default='0'
    )

    advance_pay = fields.Monetary(
        '预付房款',
        'currency_id',
    )

    currency_id = fields.Many2one(
        'res.currency',
        default=lambda self: self.env.user.company_id.currency_id,
    )  # price helper

    secrecy_home = fields.Boolean(
        '保密房'
    )

    remind = fields.Boolean(
        '到预离时间提前30分钟弹出提醒消息',
    )

    house_ids = fields.One2many(
        'check.house',
        'guest_id',
        string='House info',
        required=True,
        ondelete='set null',
    )

    # domain = [("Stage", "=", "True")

    # 关联房间信息
    # sequence = fields.Integer(
    #     'Sequence'
    # )
    #
    #
    # house_num = fields.Char(
    #     '房间号',
    #     related='house_ids.house_num'
    # )
    #
    # house_name = fields.Char(
    #     '房间名称',
    #     related='house_ids.name',
    # )
    #
    # house_type = fields.Selection(
    #     [
    #         ('0', '单人房'),
    #         ('1', '双人房'),
    #         ('2', '总统套房')
    #     ],
    #     '房间类型', relate='house_ids.house_type',
    # )
    #
    # pre_price = fields.Monetary(
    #     '预设单价',
    #     'currency_id',
    #     related='house_ids.pre_price'
    # )
    #
    # currency_id = fields.Many2one(
    #     'res.currency',
    #     default=lambda self: self.env.user.company_id.currency_id,
    # )
    #
    # dis_rate = fields.Float(
    #     '折扣率(%)',
    #     readonly=True,
    # )
    #
    # dis_price = fields.Monetary(
    #     '惠后价格',
    #     'currency_id',
    # )
    # currency_id = fields.Many2one('res.currency',
    #                               default=lambda self: self.env.user.company_id.currency_id
    #                               )  # price helper
    #
    #
    #
    #
    # De_time = fields.Date(
    #     '预离时间',
    #     related='house_ids.De_time'
    # )

    Stage = fields.Boolean(
        "状态",
        related='house_ids.Stage'
    )

    # 消费功能
    Total_consume = fields.Monetary(
        '已消费金额',
        'currency_id',
        default=0,
    )
    currency_id = fields.Many2one('res.currency',
                                  default=lambda self: self.env.user.company_id.currency_id
                                  )  # price helper

    # 入住时间
    # now_time = fields.Date(
    #     '入住时间',
    #     default=lambda self: self.create_time
    # )

#
# class HouseLine(models.Model):
#     _name = 'check.house.line'
#     _description = 'check house'
#     _rec_name = 'name'
#
#
#     @api.one
#     @api.depends('pre_price', 'dis_rate')
#     def _compute_discount_price(self):
#         for line in self:
#             line.dis_price = line.pre_price * (1 - line.dis_rate / 100)
#
#
#
#     guest_id = fields.Many2one(
#         'check.guest'
#     )
#
#     house_id = fields.Many2one(
#         'check.house',
#         required=True,
#         string='房间名称'
#     )
#
#     sequence = fields.Integer(
#         'Sequence'
#     )
#
#
#     house_num = fields.Char(
#         '房间号',
#         related='house_id.house_num'
#     )
#
#     name = fields.Char(
#         '房间名称',
#         related='house_id.name',
#     )
#
#     house_type = fields.Selection(
#         [
#             ('0', '单人房'),
#             ('1', '双人房'),
#             ('2', '总统套房')
#         ],
#         '房间类型', relate='house_id.house_type',
#     )
#
#     pre_price = fields.Monetary(
#         '预设单价',
#         'currency_id',
#         related='house_id.pre_price'
#     )
#     currency_id = fields.Many2one('res.currency')  # price helper
#
#     dis_rate = fields.Float(
#         '折扣率(%)',
#         readonly=True,
#     )
#
#     dis_price = fields.Monetary(
#         '惠后价格',
#         'currency_id',
#     )
#     currency_id = fields.Many2one('res.currency')  # price helper
#
#
#
#
#     De_time = fields.Date(
#         '预离时间',
#         related='house_id.De_time'
#     )
#
#     br_num = fields.Integer(
#         '早餐数',
#         related='house_id.br_num'
#     )
